import java.util.ArrayList;
import java.util.List;

public class demo2 {
    public static void main(String[] args) {
        List<String> list1 = new ArrayList<String>();
        list1.add("张无忌");
        list1.add("张三丰");
        list1.add("张大");
        list1.add("张二");
        list1.add("吴启益");


        //1.把所有以"张"开头的元素存储到新集合中
        ArrayList<String> list2 = new ArrayList<>();
        for (String name : list1) {
            if(name.startsWith("张")){
                list2.add(name);
            }
        }

        //2.把"张"开头的，长度为3的元素再存储到新集合中
        ArrayList<String> list3 = new ArrayList<>();
        for (String name : list2) {
            if(name.length() == 3){
                list3.add(name);
            }
        }

        //3.遍历打印最终结果
        System.out.println("原本方法");
        for (String name : list3) {
            System.out.println(name);
        }

        System.out.println("stream");
        list1.stream().filter(name -> name.startsWith("张"))
                .filter(name -> name.length() >= 3)
                .forEach(name -> System.out.println(name));
    }
}
